<?php

/**
 * model_fav
 */

class Model_fav extends YOU {

	public function __construct()
	{
		parent::__construct();
	}

		/** 读取总数 **/
	public function count()
	{
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_fav`");
		return (int)$row['count'];
	}
	
	
	/** 读取成配置 **/
	public function getIni()
	{
		$fav_lists = $this->getAll();
		foreach ($fav_lists as $key => $value){
			$fav[$value['fav_id']] = $value['fav_name'];
		}

		return $fav;
	}

	/** 读取列表 **/
	public function getAll($field = "*")
	{
		$fav_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_fav` ");

		return $fav_lists;
	}

	/** 读取信息 **/
	public function getInfo($fav_id, $field = "*")
	{
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_fav` WHERE fav_id='{$fav_id}' ");

		return $data;
	}
	/** 我的资源表->查找->收藏表表信息 **/
	public function getFav($resource_id, $user_id, $field = "*")
	{	
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_fav` WHERE resource_id='{$resource_id}' AND user_id={$user_id}");
		if (empty($data)) {
			return $data = 0;
		}else{
			return $data;
		}
		
	}

	
	
}



?>